<div id="instruction" style="position:absolute;top:100px;left:250px;background:#f9f9f9;width:920px;height:500px;z-index:999;padding: 0px;">
	<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix">
		<span class="ui-jqgrid-title">Инструкция

		</span>
	</div>
<div id="help_content" style="padding: 10px;border:1px double black;" align=center>
	<iframe src="/upload/help.html" width=900px height=430px>
	</iframe>
	<div id="help_end" align=center>
	<input type="button" style="right:0" value="Close" onClick="showInstruction(false); return false;">
</div>
</div>
</div>

<div id="addMonth" style="position:absolute;top:300px;left: 50%;margin-left: -250px;background:#f9f9f9;width:500px;height:172px;z-index:999;padding: 0px;">
<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix">
		<span class="ui-jqgrid-title">Ввод данных за</span><span id="month"></span>
	</div>
	<div id="help_content" style="padding: 10px;border:1px double black;" align=left>
		<table>
			<tr>
				<td width=70px>
				&nbsp;
				</td>
				<td align=center width=70px>
					SNGL
				</td>
				<td align=center width=70px>
					DBL
				</td>
				<td align=center width=70px>
					TRPL
				</td>
				<td align=center width=70px>
					CHLD
				</td>
				<td align=center width=70px>
					HB
				</td>
				<td width=70px>
				&nbsp;
				</td>
			</tr>
			<tr>
				<td>
				&nbsp;
				</td>
				<td align=center>
					<input type="text" style="width:60px" id="aSNGL">
				</td>
				<td align=center>
					<input type="text" style="width:60px" id="aDBL">
				</td>
				<td align=center>
					<input type="text" style="width:60px" id="aTRPL">
				</td>
				<td align=center>
					<input type="text" style="width:60px" id="aCHLD">
				</td>
				<td align=center>
					<input type="text" style="width:60px" id="aHB">
				</td >
				<td>
				&nbsp;
				</td>
			</tr>
			<tr>
				<td align=center>
					Пн
				</td>
				<td align=center>
					Вт
				</td>
				<td align=center>
					Ср
				</td>
				<td align=center>
					Чт
				</td>
				<td align=center>
					Пт
				</td>
				<td align=center>
					Сб
				</td>
				<td align=center>
					Вс
				</td>
			</tr>
			<tr>
				<td align=center>
					<input type=checkbox id="pn" checked>
				</td>
				<td align=center>
					<input type=checkbox id="vt" checked>
				</td>
				<td align=center>
					<input type=checkbox id="sr" checked>
				</td>
				<td align=center>
					<input type=checkbox id="ch" checked>
				</td>
				<td align=center>
					<input type=checkbox id="pt" checked>
				</td>
				<td align=center>
					<input type=checkbox id="sb" checked>
				</td>
				<td align=center>
					<input type=checkbox id="vs" checked>
				</td>
			</tr>
		</table>
<br>
		<div id="help_end" align=center>
			<input type="button" Value="Добавить"  onClick="save();">
			<input type="button" style="right:0" value="Закрыть" onClick="jQuery('#addMonth').hide(); return false;">
		</div>
	</div>
	<div id="data" style="display:none;">
		<span id="d2Year"></span>
		<span id="d2Month"></span>
		<span id="d2Table"></span>
		<span id="d2Tour"></span>
	</div>
</div>
<script>jQuery('#instruction').hide();jQuery('#addMonth').hide();</script>
<table border=0 width=100%>
<tr>
	<td width=50% align=left>
		Даты тура

		<select name="tourList" id="tourList" onchange="window.location = '/admin/tourdates/'+document.getElementById('tourList').value;">

		<?php foreach($list_tours as $item): ?>
			<option value="<?php echo $item['id'];?>" <?php if($item['selected']==1)echo 'selected'?>><?php echo $item['name'];?>
		<?php endforeach; ?>
		</select>
	</td>
	<td width=50% align=right>
		<br>
	<p style="font-size:11px;font-color:'#b2b2b2';">
	Перед загрузкой данных сохраненных в файле формата<br> Microsoft Office Excel, пожалуйста ознакомтесь с <u><a style="font-size:11px;font-color:'#ffb2b2';" onClick="showInstruction(true); return false;">инструкцией!</a></u>
	</p>
		<form name="form" action="" method="POST" enctype="multipart/form-data">
		<input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input">
		<input type='hidden' name='some' value='val'>
		<button class="button" id="buttonUpload" onclick="ajaxFileUpload2(<?php echo $tourId; ?>);return false;">Загрузить</button></td>

		</form>


	</td>
</tr>
</table>


<table id='parent' width=98% border=1px cellspacing=0 cellpadding=0 bordercolor="#f1f1f1">
	<tr>
		<td colspan=<?php echo 13-date('m'); ?> align=center bgcolor="#f2f2f2">
			<?php
				echo date('Y')."г."; //Выводим текущий год
			?>
		</td>
		<td colspan=<?php echo 5-12+date('m'); ?> align=center bgcolor="#f9f9f9">
			<?php
				echo (date('Y')+1)."г."; // Выводим следующий год
			?>
		</td>
	</tr>
	<tr>
		<?php
		$mm=date('m');
		$yy=date('Y');
		$monthA=array("Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь");
		$dayA=array("Вс","Пн","Вт","Ср","Чт","Пт","Сб");
		for($i=0;$i<6;$i++)
		{
			$sp="";
			$spe="";
			$color="#fafbf0";
			if($month==$mm)
			{
				$sp="<span id=mMonth>";
				$spe="</span>";
				$color="#ffa193";
			}

			echo "<td align=center bgcolor='$color'>\n";
			echo "<a  href='/admin/tourdates/$tourId/$yy/$mm' >".$sp.$monthA[$mm-1].$spe."</a>\n";
			echo "</td>\n";
			if($mm==12)
			{
				$mm=1;
				$yy++;
			}
			else
			{
				$mm++;
			}
			//$mm==12?$mm=1:{};
		}
		?>

	</tr>
	<tr>
		<td colspan=6>
			<table width=100%>
				<tr>
					<td width=5% valign="top">
						<input type="button" value="+" style="width:20px;height:40px" onClick="addMonthData(<? echo $year; ?>,<? echo $month; ?>,<? echo $tourId; ?>,3)">
						<br>
						<input type=button value="-" style="width:20px;height:40px" onClick="clearTable(<? echo $year; ?>,<? echo $month; ?>,<? echo $tourId; ?>,3)">
					</td>
					<td align=center width="80%">
						<table id="tableTours3"></table>
						<div id="pagerTours3"></div>
					</td>
					<td width=5%>
						&nbsp;
					</td>
				</tr>
				<tr>
					<td width=5% valign="top">
						<input type="button" value="+" style="width:20px;height:40px" onClick="addMonthData(<? echo $year; ?>,<? echo $month; ?>,<? echo $tourId; ?>,4)">
							<br>
						<input type=button value="-" style="width:20px;height:40px" onClick="clearTable(<? echo $year; ?>,<? echo $month; ?>,<? echo $tourId; ?>,4)">
					</td>
					<td>
						<table id="tableTours4"></table>
						<div id="pagerTours4"></div>
					</td>
					<td width=5%>
						&nbsp;
					</td>
				</tr>
				<tr>
					<td width=5% valign="top">
						<input type="button" value="+" style="width:20px;height:40px" onClick="addMonthData(<? echo $year; ?>,<? echo $month; ?>,<? echo $tourId; ?>,5)">
						<br>
						<input type=button value="-" style="width:20px;height:40px" onClick="clearTable(<? echo $year; ?>,<? echo $month; ?>,<? echo $tourId; ?>,5)">
					</td>
					<td>
						<table id="tableTours5"></table>
						<div id="pagerTours5"></div>
					</td>
					<td width=5%>
						&nbsp;
					</td>
				</tr>

			</table>
		</td>
	</tr>
</table>


<script>
<?php
	$m=$month;
	$y=$year;
	$n=($m!=2?(($m%2)^($m>7))+30:(!($y%400)||!($y%4)&&($y%25)?29:28));

	for($table=3;$table<=5;$table++)
	{
	?>
	var lastsel<?php echo $table; ?>="";
	jQuery("#tableTours<?php echo $table; ?>").jqGrid({
   		url:'/admin/datatour/<? echo $year; ?>/<? echo $month; ?>/<? echo $tourId; ?>/<?php echo $table; ?>',
        editurl:'/admin/editdatatour/<? echo $year; ?>/<? echo $month; ?>/<? echo $tourId; ?>/<?php echo $table; ?>',
		datatype: "json",
        mtype: 'GET',
		colNames:['ID','<?php
		echo $table."*'";
		for ($i=1;$i<=$n;$i++)
		{
			$day= date('w', mktime(0, 0, 0,  $month,$i, $year));
			echo ",'<u>".$i."</u><br>".$dayA[$day]."'";
		}
		?>],
   		colModel:[
   		{name:'id',index:'id', width:55, align:"center", hidden:true},
		{name:'type',index:'type', width:120,editable:false, align:"center",edittype:"text",editrules:{required:true},searchoptions: { sopt: [] }},
		<?php
		for ($i=1;$i<=$n;$i++)
		{
			echo "{name:'d".$i."',index:'".$i."', width:60, align:'center',editable:true,editrules:{required:false,integer:true},editoptions: { size: '20', maxlength: '30'}, searchoptions: { sopt: ['eq','ne','lt','gt'] }},";
		}
		?>
	   	],
   		rowNum:5,
   		onSelectRow: function (id) {
                if (id && id !== lastsel<?php echo $table; ?>) {

                   	jQuery('#tableTours<?php echo $table; ?>').jqGrid('restoreRow', lastsel<?php echo $table; ?>);
                	jQuery('#tableTours<?php echo $table; ?>').jqGrid('editRow', id, true);
                    lastsel<?php echo $table; ?> = id;
                }
            },
  	 	rowList:[],
  	 	pager: '#pagerTours<?php echo $table; ?>',
 	    viewrecords: true,
 	    caption:"Даты тура для отелей <?php echo $table; ?>*",
 	    width:1250,
 	    height:115
	});
	jQuery("#tableTours<?php echo $table; ?>").jqGrid('navGrid','#pagerTours<?php echo $table; ?>',{edit:true,add:false,del:true,search:false});
	<?php
	}
	?>


 </script>
	<script type="text/javascript" src="/js/admin/ajaxfileupload.js"></script>
<script>

function clearTable(year,month,tourid,table)
{
if(confirm("Вы действительно хотите удалить все данные за этот месяц?")==true) {
	var url="/admin/deldatatour/"+year+"/"+month+"/"+tourid+"/"+table;
  	$.ajax({
    url: url,             // указываем URL и
    dataType : "json",                     // тип загружаемых данных
    success: function (data, textStatus) { // вешаем свой обработчик на функцию success
 		 		jQuery('#tableTours'+table).trigger("reloadGrid");
    			}
	});
	}
}

function addMonthData(year,month,tourid,table)
{
	jQuery('#addMonth').show();
	jQuery('#month').replaceWith(jQuery('#mMonth').text());
	jQuery('#d2Month').text(month+"");
	jQuery('#d2Year').text(year+"");
	jQuery('#d2Tour').text(tourid+"");
	jQuery('#d2Table').text(table+"");
}
function save()
{
	jQuery('#addMonth').hide();
 	$.ajax({
		  type: 'POST',
		  url:"/admin/addMonthPrice",
		  data: {month:jQuery('#d2Month').text(),
		  		year:jQuery('#d2Year').text(),
				tourid:jQuery('#d2Tour').text(),
				type:jQuery('#d2Table').text(),
				SNGL:jQuery('#aSNGL').val(),
				DBL:jQuery('#aDBL').val(),
				TRPL:jQuery('#aTRPL').val(),
				CHLD:jQuery('#aCHLD').val(),
				HB:jQuery('#aHB').val(),
				pn:$('#pn').attr('checked'),
				vt:$('#vt').attr('checked'),
				sr:$('#sr').attr('checked'),
				ch:$('#ch').attr('checked'),
				pt:$('#pt').attr('checked'),
				sb:$('#sb').attr('checked'),
				vs:$('#vs').attr('checked')
				},
		  success: function(){
		  	jQuery('#tableTours'+jQuery('#d2Table').text()).trigger("reloadGrid");
		  },
		  dataType: "json"
	});
}
function showInstruction(val)
{
if(val)
{
	jQuery('#instruction').show();
}
else
{
	jQuery('#instruction').hide();
}
}
</script>